package com.lmj.serviceribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;


    @HystrixCommand(fallbackMethod = "hiError")
    public String getHi(String name){
        String url = "http://SERVICE-HI/hi?name={name}";
        Map<String,String> params = new HashMap<String,String>();
        params.put("name",name);
        return restTemplate.getForObject(url,String.class,params);
    }

    public String hiError(String name){
        return "This an error!"+name;
    }
}
